<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/11/2 0002
 * Time: 下午 6:32
 */

namespace app\mobile\controller;


use think\Db;

class News extends MoBase
{
    public function cate(){
        $pid = $this->request->param('pid');
        $page = $this->request->post('page') ?: 1;

        $pcate = Db::name('index_block')->field('id,title as name,english_title as english_name')->find(1);
        $cur = Db::name('news_cate')->where(['id'=>$pid,'is_deleted'=>1,'status'=>1])->field('id,title as name')->find();
        $catelist = Db::name('news_cate')->where(['is_deleted'=>1,'status'=>1])->field('id,title as name')->order('sort desc,id desc')->select();
        $news = Db::name('news')->where(['is_deleted'=>1,'status'=>1,'pid'=>$pid])->order('sort desc,id desc')->hidden('content')->select();
        foreach ($news as $k=>$n){
            $news[$k]['link'] = json_decode($n['link'], true);
        }

        $this->assign([
            'pcate'=>$pcate,
            'cur'=>$cur,
            'catelist'=>$catelist,
            'news'=>$news,
        ]);
        if ($pid==3){
            return view('cates');
        }else{
            return view();
        }
    }

    public function index(){
        $id = $this->request->param('id');
        $news = Db::name('news')->where('id', $id)->find();
        $this->assign([
            'news'=>$news
        ]);
        return view();
    }
}